#include "MsgPublish.h"

namespace RobotControl{
namespace Common{

MsgPublish::MsgPublish(zmq::context_t *ctx)
	: m_socket(*ctx, ZMQ_PUB)
{
	m_hwm = 3;
}

/// \brief 配置主题
bool MsgPublish::config(const std::string &topic)
{
#if 0
	try{
		m_socket.bind(topic);
	}
	catch(std::exception &e)
	{
		//Log::RobotLog(Log::Error) << "error: " << e.what() << std::endl;
		return false;
	}
#else
    // 连接失败直接异常抛出
    m_socket.bind(topic);
    m_socket.setsockopt(ZMQ_SNDHWM, &m_hwm, sizeof(m_hwm));
#endif
	return true;
}

/// \brief 配置主题
/// \param[in] hwm: 消息溢出阈值
bool MsgPublish::config(const std::string &topic, const int32_t hwm)
{
	m_hwm = hwm;
	return config(topic);
}

/// \brief 配置主题
bool config(const std::string &topic, const int32_t hwm);

/// \brief 请求数据
/// \param[in] req: 请求的数据
/// \param[in] rep: 应答的数据
void MsgPublish::publish(zmq::message_t &pub)
{
	m_socket.send(pub);
}

}	// Common
}	// RobotControl
